package reflect;

/**
 * JDK5之后推出的一个特性:变长参数
 */
public class ArgDemo {
    public static void main(String[] args) {
        doSome(1);
        doSome(1,"a");
        doSome(1,"a","b");
        doSome(1,"a","b","c");
        doSome(1,"a","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c","b","c");
    }

    /**
     * 声明变长参数的语法:类名... 变量名
     * 注意:变长参数只能是方法的[最后一个]参数
     *
     * 变长参数是编译器认可的,编译后变长参数会被改为对应类型的数组:
     * public static void doSome(int a,String[] s){...}
     *
     * 调用时所有变长参数的实参会以一个数组形式传入
     * doSome(1,"a","b","c"); ---> doSome(1,new String[]{"a","b","c"});
     *
     * @param s
     */
    public static void doSome(int a,String... s){
        System.out.println(s.length);//s实际上是一个String类型数组
    }

}
